package com.doit.demo02;

@SuppressWarnings("all")
public class test02 {
    public static void main(String[] args) {
        int [] arr = {3,8,2,5,0};
        //冒泡排序
        for (int i = arr.length-1; i >0 ; i--) {
            for (int j = 0; j <i ; j++) {
                if(arr[j]>arr[j+1]) {
                    int temp = arr[j];
                    arr[j]=arr[j+1];
                    arr[j+1]=temp;
                }
            }
        }
//        for (int a:arr)
//        {
//            System.out.println(a);
//        }
        to(arr);
        int [] arr2= {3, 5, 8, 5, 4,6};
        //乃
        for(int j=0;j<arr2.length-1;j++)
        {
            for (int i=0;i<arr2.length-j-1;i++)//把大的放后面
            {
                if(arr2[i]>arr2[i+1]) {
                    int temp = arr2[i];
                    arr2[i]=arr2[i+1];
                    arr2[i+1]=temp;
                }
            }
        }
        to(arr2);

    }
    private static void to(int[] a) {
        StringBuilder s = new StringBuilder();
        s.append("[");
        for(int b:a)
        {
            s.append(b);
            if(b==a[a.length-1])
                s.append("]");
            else
                s.append(",");
        }
        System.out.println(s.toString());
    }
}
